import Vue from 'vue'
import store from './store'
import App from './App'
import cuCustom from './components/head/cu-custom.vue'
import flowCustom from './components/flow/index.vue'
import Router   from '@/common/router/uni_router'
Vue.use(Router)
import ComFunJS from '@/common/comfun/ComFun'
Vue.prototype.$ComFunJS = ComFunJS  	
const router = new Router()
Vue.component('cu-custom',cuCustom)
Vue.component('flow',flowCustom)
import bar from '@/components/bar/index'
Vue.component('bar',bar)
/**
 *  因工具函数属于公司资产, 所以直接在Vue实例挂载几个常用的函数
 *  所有测试用数据均存放于根目录json.js
 *  
 *  css部分使用了App.vue下的全局样式和iconfont图标，有需要图标库的可以留言。
 *  示例使用了uni.scss下的变量, 除变量外已尽量移除特有语法,可直接替换为其他预处理器使用
 */

// #ifdef MP
Vue.mixin({
  onLoad: function () {
	wx.showShareMenu();
  }
})
// #endif
router.beforeEach(function(to, from, next) {
	let norouter = []
	uni.getStorage({
		key: 'tokenxm',
		complete: function(res) {
			console.log('前置守卫',to)
			if (!res && to.page!='/pages/person/bind') {
			// 测试小程序跳转
				next({page: '/pages/person/bind',params: {},method: 'reLaunch'})
			} else {
				next()
			}			
		},
	})
})	



const msg = (title, duration=1500, mask=false, icon='none')=>{
	//统一提示方便全局修改
	if(Boolean(title) === false){
		return;
	}
	uni.showToast({
		title,
		duration,
		mask,
		icon
	});
}
const prePage = ()=>{
	let pages = getCurrentPages();
	let prePage = pages[pages.length - 2];
	// #ifdef H5
	return prePage;
	// #endif
	return prePage.$vm;
}
Vue.config.productionTip = false
Vue.prototype.$fire = new Vue();
Vue.prototype.$store = store;
Vue.prototype.$api = {msg,prePage};

App.mpType = 'app'

const app = new Vue({
    ...App
})
app.$mount()